package fairygui.editor.gui
{
   public class EUIObjectFactory
   {
      
      public static var constructingDepth:int;
       
      
      public function EUIObjectFactory()
      {
         super();
      }
      
      public static function createObject(param1:EPackageItem, param2:int = 0) : EGObject
      {
         var pi:EPackageItem = param1;
         var editMode:int = param2;
         var cls:Object = getClassByType(pi.type);
         if(cls == null)
         {
            return null;
         }
         var g:EGObject = new cls();
         g.pkg = pi.owner;
         g.editMode = editMode;
         g.underConstruct = true;
         g.packageItem = pi;
         g.packageItemVersion = pi.version;
         constructingDepth++;
         try
         {
            g.create();
         }
         finally
         {
            constructingDepth--;
            g.underConstruct = false;
         }
         return g;
      }
      
      public static function createObject2(param1:EUIPackage, param2:String, param3:int = 0) : EGObject
      {
         var pkg:EUIPackage = param1;
         var type:String = param2;
         var editMode:int = param3;
         var cls:Object = getClassByType(type);
         if(cls == null)
         {
            return null;
         }
         var g:EGObject = new cls();
         g.pkg = pkg;
         g.editMode = editMode;
         g.underConstruct = true;
         constructingDepth++;
         try
         {
            g.create();
         }
         finally
         {
            constructingDepth--;
            g.underConstruct = false;
         }
         return g;
      }
      
      public static function createExtention(param1:EUIPackage, param2:String) : ComExtention
      {
         var _loc3_:ComExtention = null;
         var _loc4_:Object = null;
         switch(param2)
         {
            case "Label":
               _loc3_ = new EGLabel();
               break;
            case "Button":
               _loc3_ = new EGButton();
               break;
            case "ProgressBar":
               _loc3_ = new EGProgressBar();
               break;
            case "ScrollBar":
               _loc3_ = new EGScrollBar();
               break;
            case "Slider":
               _loc3_ = new EGSlider();
               break;
            case "ComboBox":
               _loc3_ = new EGComboBox();
               break;
            default:
               _loc4_ = param1.project.editorWindow.plugInManager.comExtensions[param2];
               if(_loc4_)
               {
                  return createExtention(param1,_loc4_.superClassName);
               }
               break;
         }
         if(_loc3_)
         {
            _loc3_._type = param2;
         }
         return _loc3_;
      }
      
      public static function getClassByType(param1:String) : Object
      {
         var _loc2_:Object = null;
         switch(param1)
         {
            case ObjectTypes.IMAGE:
               _loc2_ = EGImage;
               break;
            case ObjectTypes.SWF:
               _loc2_ = EGSwfObject;
               break;
            case ObjectTypes.MOVIECLIP:
            case "jta":
               _loc2_ = EGMovieClip;
               break;
            case ObjectTypes.COMPONENT:
               _loc2_ = EGComponent;
               break;
            case ObjectTypes.TEXT:
               _loc2_ = EGTextField;
               break;
            case ObjectTypes.RICHTEXT:
               _loc2_ = EGRichTextField;
               break;
            case ObjectTypes.GROUP:
               _loc2_ = EGGroup;
               break;
            case ObjectTypes.LIST:
               _loc2_ = EGList;
               break;
            case ObjectTypes.GRAPH:
               _loc2_ = EGGraph;
               break;
            case ObjectTypes.LOADER:
               _loc2_ = EGLoader;
         }
         return _loc2_;
      }
   }
}
